// pages/user/myIntegral/myIntegral.js
const WxParse = require('../../../wxParse/wxParse.js');

Page({

    /**
     * 页面的初始数据
     */
    data: {
        isRuleShow: false,
        setting: null,
        data: [],
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) {
        this.onPullDownRefresh();
    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function() {
        this.loadData(1).finally(() => {
            wx.stopPullDownRefresh();
        });
    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function() {
        if (!this.data.hasMore) return;

        const page = this.data.page + 1;
        this.loadData(page);
    },

    // 加载数据列表
    loadData: function(page) {
        return wx.http.post('api/user.Integral/index', {}).then((res) => {
            res = res.data.data;
            const list = res.list;
            const hasMore = list.data.length >= res.per_page;
            const data = page > 1 ? this.data.data.concat(list.data) : list.data;

            // 渲染富文本
            // const settingDescribe = res.setting.describe;
            // delete res.setting.describe;

            this.setData({
                setting: res.setting,
                user: res.user,
                page: page,
                hasMore: hasMore,
                data: data,
            }, () => {
                // WxParse.wxParse('setting.describe', 'html', settingDescribe, this);
            });
            return res.data;
        }, (err) => {
            console.warn("api/user.Integral/index", err)
        });
    },

});
